<template>
  <div class="userbox" v-if="dataList.count">
    <div
      class="top"
      :style="`background:url(${dataList.app_background==''?'./assets/jkl.jpg':dataList.app_background}?x-oss-process=image/resize,m_mfit,w_720) no-repeat center/cover`"
    >
      <div class="content">
        <div class="backmore">
          <i class="iconfont icon-fanhui" @click="$router.back()"></i>
          <i class="iconfont icon-gengduo"></i>
        </div>
        <div class="usericon">
          <img :src="dataList.avatar | picUrl" alt="" />
        </div>
        <div class="userinfo">
          <p class="username">{{ dataList.username }}</p>
          <p class="occu">
            {{ dataList.occupation }}·<span v-if="dataList.location">{{
              dataList.location.province
                ? dataList.location.province.name
                : dataList.location.country.name
            }}</span>
          </p>
          <p class="local">{{ dataList.verify_description }}</p>
        </div>
        <div class="rest">
          <div class="itembox">
            <div class="item">
              <span>{{ dataList.count.count_popularity | count }}</span>
              <span>人气</span>
            </div>
            <div class="item">
              <span>{{ dataList.count.count_follower | count }}</span>
              <span>粉丝</span>
            </div>
            <div class="item">
              <span>{{ dataList.count.count_followee | count }}</span>
              <span>关注</span>
            </div>
          </div>
          <div class="right">
            <div class="coll">联系合作</div>
            <div @click.stop="attention" class="guanzhu" v-if="attentionList.indexOf(ids)==-1">关注</div>
            <div @click.stop="attention" class="guanzhu guanzhued" v-else>已关注</div>
          </div>
        </div>
      </div>
    </div>
    <div class="bottom">
      <van-tabs class="mytabs" v-model="activeName" @change="onChange" sticky>
        <van-tab title="作品" name="articles">
          <van-dropdown-menu class="mydrop" sticky>
            <van-dropdown-item v-model="value1" :options="option1" />
          </van-dropdown-menu>
          <div
            class="worksbox"
            v-if="needData.list && activeName == 'articles'"
          >
            <FinddeItem :list="needData.list"></FinddeItem>
          </div>
          <MyLoading v-else></MyLoading>
        </van-tab>
        <van-tab title="专辑" name="collections">
          <div v-if="needData.list">
            <div
              v-if="needData.list.length && activeName == 'collections'"
              class="albumbox"
            >
              <div
                class="albumitem"
                v-for="(item, index) in needData.list"
                :key="index"
              >
                <p class="top-1"></p>
                <p class="top-2"></p>
                <div class="albumimgbox">
                  <img :src="item.cover_url | picUrl" alt="" />
                  <i class="iconfont icon-copy-fill"></i>
                </div>
                <div class="title">{{ item.title }}</div>
                <div class="foot">
                  作品{{
                    item.count.count_article | count
                  }}&nbsp;&nbsp;·&nbsp;&nbsp;浏览{{
                    item.count.count_viewed | count
                  }}&nbsp;&nbsp;·&nbsp;&nbsp;赞{{
                    item.count.count_liked | count
                  }}
                </div>
              </div>
            </div>
            <div class="kong" v-else>
              <p>没有发布专辑</p>
            </div>
          </div>
          <MyLoading v-else></MyLoading>
        </van-tab>
        <van-tab title="喜欢" name="articles-approved">
          <div v-if="needData.list">
            <div
              v-if="
                needData.list.length != 0 && activeName == 'articles-approved'
              "
              class="box"
            >
              <div
                class="boxitem"
                v-for="(item, index) in needData.list"
                :key="index"
              >
                <uiBigCard :item="item"></uiBigCard>
              </div>
            </div>
            <div class="kong" v-else>
              <p>没有添加喜欢</p>
            </div>
          </div>
          <MyLoading v-else></MyLoading>
        </van-tab>
        <van-tab title="资料" name="info">
          <div class="infobox">
            <div class="infotitle">基本资料</div>
            <div class="infoitem">
              <div class="itemtitle">性别</div>
              <div class="itemcont" v-if="dataList.sex == 1">男</div>
              <div class="itemcont" v-if="dataList.sex == 2">女</div>
              <div
                class="itemcont"
                v-if="dataList.sex != 2 && dataList.sex != 1"
              >
                未知
              </div>
            </div>
            <div class="infoitem">
              <div class="itemtitle">年龄</div>
              <div class="itemcont" v-if="dataList.birthday">
                {{ thisyear - dataList.birthday.slice(0, 4) }}
              </div>
              <div class="itemcont" v-else>未知</div>
            </div>
            <div class="infoitem">
              <div class="itemtitle">所在地区</div>
              <div class="itemcont" v-if="dataList.location">
                {{
                  dataList.location.province
                    ? dataList.location.province.name
                    : dataList.location.country.name
                }}
              </div>
              <div class="itemcont" v-else>未知</div>
            </div>
            <div class="infoitem">
              <div class="itemtitle">简介</div>
              <div class="itemcont" v-if="dataList.about">
                {{ dataList.about }}
              </div>
              <div class="itemcont" v-else>TA还没有留下任何讯息…</div>
            </div>
            <div class="infotitle">认证信息</div>
            <div class="infoitem">
              <div class="itemtitle">认证身份</div>
              <div class="itemcont" v-if="dataList.occupation">
                {{ dataList.occupation }}
              </div>
              <div class="itemcont" v-else>未知</div>
            </div>
            <div class="infoitem">
              <div class="itemtitle">入行年份</div>
              <div class="itemcont" v-if="dataList.entry_year">
                {{ dataList.entry_year }}
              </div>
              <div class="itemcont" v-else>未知</div>
            </div>
            <div class="infoitem">
              <div class="itemtitle">认证描述</div>
              <div class="itemcont" v-if="dataList.verify_description">
                {{ dataList.verify_description }}
              </div>
              <div class="itemcont" v-else>没有描述</div>
            </div>
          </div>
        </van-tab>
      </van-tabs>
    </div>
  </div>
  <MyLoading v-else></MyLoading>
</template>

<script>
import Vue from "vue";
import FinddeItem from "@/components/FinddeItem.vue";
import uiBigCard from "@/components/uiBigCard.vue";
import MyLoading from "@/components/MyLoading.vue";
import { Tab, Tabs } from "vant";
import { DropdownMenu, DropdownItem } from "vant";
import {mapState} from "vuex";

Vue.use(DropdownMenu);
Vue.use(DropdownItem);
Vue.use(Tab);
Vue.use(Tabs);
export default {
  data() {
    return {
      dataList: {},
      value1: "",
      activeName: "articles",
      needData: {},
      page: 1,
      ids:0,
      album: [],
      thisyear: null,
      option1: [
        { text: "默认排序", value: "" },
        { text: "热门排序", value: "view" },
        { text: "最新上传", value: "new" },
      ],
    };
  },
  components: {
    FinddeItem,
    uiBigCard,
    MyLoading,
  },
  computed:{
    ...mapState(["attentionList"])
  },
  created() {
    this.thisyear = new Date().getFullYear();
    this.ids = this.$route.query.id*1
    this.axios
      .get("https://apis.netstart.cn/xpc/user/" + this.$route.query.id)
      .then((res) => {
        this.dataList = res.data.data;
      });
    this.axios
      .get(
        "https://apis.netstart.cn/xpc/user/" +
          this.$route.query.id +
          "/" +
          this.activeName +
          "?type=public&order=" +
          this.value1 +
          "&is_hide_in_space=0&return_struct_type=user_home&page=" +
          this.page
      )
      .then((res) => {
        this.needData = res.data.data;
      });
  },
  methods: {
    attention(){
      this.$store.commit('addAttention',{id:this.ids})
    },
    onChange(name) {
      if (name != "info") {
        this.needData = {};
        console.log(name);
        if (name == "worksbox") {
          this.axios
            .get(
              "https://apis.netstart.cn/xpc/user/" +
                this.$route.query.id +
                "/" +
                this.activeName +
                "?type=public&order=" +
                n +
                "&is_hide_in_space=0&return_struct_type=user_home&page=" +
                this.page
            )
            .then((res) => {
              this.needData = res.data.data;
              console.log(this.needData);
            });
        } else {
          this.axios
            .get(
              "https://apis.netstart.cn/xpc/user/" +
                this.$route.query.id +
                "/" +
                name
            )
            .then((res) => {
              this.needData = res.data.data;
              console.log(this.needData);
            });
        }
      }
    },
  },
  watch: {
    value1: function (n) {
      this.axios
        .get(
          "https://apis.netstart.cn/xpc/user/" +
            this.$route.query.id +
            "/" +
            this.activeName +
            "?type=public&order=" +
            n +
            "&is_hide_in_space=0&return_struct_type=user_home&page=" +
            this.page
        )
        .then((res) => {
          this.needData = res.data.data;
        });
    },
    $route: function (n) {
      this.dataList = {};
      this.needData = {};
      this.thisyear = new Date().getFullYear();
      this.axios
        .get("https://apis.netstart.cn/xpc/user/" + this.$route.query.id)
        .then((res) => {
          this.dataList = res.data.data;
        });
      this.axios
        .get(
          "https://apis.netstart.cn/xpc/user/" +
            this.$route.query.id +
            "/" +
            this.activeName +
            "?type=public&order=" +
            this.value1 +
            "&is_hide_in_space=0&return_struct_type=user_home&page=" +
            this.page
        )
        .then((res) => {
          this.needData = res.data.data;
        });
    },
  },
};
</script>

<style lang="less" scoped>
.userbox {
  width: 100vw;
  height: 100%;
  background-color: #f7f7f7;
  .infobox {
    width: 100%;
    background-color: #fff;
    padding: 15px;
    padding-top: 0;
    .infotitle {
      font-weight: 600;
      font-size: 15px;
      height: 70px;
      display: flex;
      align-items: center;
      border-bottom: 1px solid #f0f0f0;
    }
    .infoitem {
      width: 100%;
      height: 50px;
      display: flex;
      align-items: center;
      .itemtitle {
        font-size: 14px;
        color: #b5b5b5;
        width: 20%;
      }
      .itemcont {
        font-size: 14px;
        flex: 1;
      }
    }
  }
  .kong {
    width: 100%;
    height: 80px;
    background-color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    color: #aaa;
  }
  .top {
    width: 100%;
    height: 50vh;
    display: flex;
    flex-wrap: wrap;
    position: 20px;
    position: relative;
    z-index: 0;
    .content {
      padding: 20px;
      position: absolute;
      z-index: 2222;
      width: 100%;
      height: 100%;
      background-color: rgba(0, 0, 0, 0.2);
      .backmore {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        i {
          font-size: 35px;
          color: white;
          &:first-child {
            font-size: 22px;
          }
        }
      }
      .usericon {
        width: 60px;
        height: 60px;
        border-radius: 50%;
        overflow: hidden;
        margin-top: 30px;
      }
      .userinfo {
        .username {
          font-size: 18px;
          font-weight: 500;
          color: white;
          margin-top: 15px;
        }
        .occu {
          margin-top: 6px;
          color: #e0e0e0;
          font-size: 13px;
        }
        .local {
          margin-top: 6px;
          color: #e0e0e0;
          font-size: 13px;
        }
      }
      .rest {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 30px;
        .itembox {
          width: 45%;
          display: flex;
          justify-content: space-between;
          align-items: center;
          .item {
            display: flex;
            flex-direction: column;
            color: white;
            justify-content: center;
            span {
              margin-bottom: 6px;
              font-size: 12px;
              &:first-child {
                font-weight: 600;
              }
            }
          }
        }
        .right {
          width: 50%;
          display: flex;
          justify-content: space-between;
          font-size: 13px;
          .coll {
            width: 46%;
            background-color: #fff;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 30px;
            border-radius: 30px;
          }
          .guanzhu {
            width: 46%;
            background-color: #e44b39;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 30px;
            color: white;
            border-radius: 30px;
            &.guanzhued {
              background-color: #666;
              color: #ddd;
            }
          }
        }
      }
    }
  }
  .bottom {
    .mytabs {
      .box {
        padding: 10px 15px;
        .boxitem {
          margin-bottom: 10px;
        }
      }
      .albumbox {
        margin-top: 10px;
        background-color: #fff;
        padding: 15px 15px;
        .albumitem {
          margin-bottom: 20px;
          .top-1 {
            width: 93%;
            background-color: #fafafa;
            height: 8px;
            margin: 0 auto;
            border-radius: 2px 2px 0 0;
          }
          .top-2 {
            width: 96%;
            background-color: #e0e0e0;
            height: 8px;
            margin: 0 auto;
            border-radius: 2px;
          }
          .title {
            margin: 10px 0;
            font-size: 15px;
            font-weight: 600;
          }
          .foot {
            font-size: 13px;
            color: #b5b5b5;
          }
          .albumimgbox {
            position: relative;
            img {
              border-radius: 10px;
              display: block;
            }
            i {
              color: white;
              font-size: 18px;
              position: absolute;
              right: 10px;
              top: 10px;
            }
          }
        }
      }
      .worksbox {
        margin-top: 10px;
        background-color: #fff;
        width: 100%;
        padding: 10px 15px;
      }
      .mydrop {
        background-color: #fff;
        /deep/.van-dropdown-menu__bar {
          box-shadow: none;
          width: 100px;
          .van-dropdown-menu__item {
            justify-content: flex-start;
            padding-left: 15px;
          }
        }
        /deep/.van-dropdown-item--down {
          left: 10px;
          top: 10px;
          width: 90px;
          // box-shadow: 0 2px 12px #d0d0d0;
          height: 135px;
          .van-cell__value {
            display: none;
          }
          .van-overlay {
            display: none;
          }
          .van-dropdown-item__content {
            top: 5px;
            max-height: 100% !important;
            border-radius: 5px;
          }
        }
      }
    }
  }
}
</style>